#include <debugprintf.h>
#include <stdio.h>
#include "..\jpeglib.h"




void main()
{
	struct jpeg_decompress_struct cinfo;
	struct jpeg_error_mgr jerr;


	cinfo.err = jpeg_std_error(&jerr);
	jpeg_create_decompress(&cinfo);



	FILE *f = fopen("testimg.jpg","rb");
	if (f==NULL)
	{
		printf("Open file error!\n");
		return;
	}

	jpeg_stdio_src(&cinfo, f);

	jpeg_read_header(&cinfo, TRUE);


	DebugPrintf("width : %d \nheight : %d \n",cinfo.image_width,cinfo.image_height);

	DebugPrintf("color space : %d\n",cinfo.jpeg_color_space);


	cinfo.out_color_space = JCS_RGB;

	//cinfo.dct_method = JDCT_IFAST;


	jpeg_start_decompress(&cinfo);


	JSAMPARRAY buffer;	/* Output row buffer */
	int row_stride;		/* physical row width in output buffer */

	/* JSAMPLEs per row in output buffer */
	row_stride = cinfo.output_width * cinfo.output_components;

	/* Make a one-row-high sample array that will go away when done with image */
	buffer = (*cinfo.mem->alloc_sarray)
		((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1);

	while (cinfo.output_scanline < cinfo.output_height) {
		/* jpeg_read_scanlines expects an array of pointers to scanlines.
		* Here the array is only one element long, but you could ask for
		* more than one scanline at a time if that's more convenient.
		*/
		(void) jpeg_read_scanlines(&cinfo, buffer, 1);

	}


	jpeg_finish_decompress(&cinfo);

	jpeg_destroy_decompress(&cinfo);

	fclose(f);

}